﻿<Application 
    x:Class="yavc.Phone.App"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:conv="clr-namespace:yavc.Phone.Lib.Util;assembly=yavc.Phone.Lib"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone">

    <!--Application Resources-->
    <Application.Resources>
        <Style x:Key="clearButtonStyle" TargetType="Button">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="Button">
                        <Grid Background="Transparent">
                            <VisualStateManager.VisualStateGroups>
                                <VisualStateGroup x:Name="CommonStates">
                                    <VisualState x:Name="Normal"/>
                                    <VisualState x:Name="MouseOver"/>
                                    <VisualState x:Name="Pressed"/>
                                    <VisualState x:Name="Disabled">
                                        <Storyboard>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="ContentContainer">
                                                <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PhoneDisabledBrush}"/>
                                            </ObjectAnimationUsingKeyFrames>
                                        </Storyboard>
                                    </VisualState>
                                </VisualStateGroup>
                            </VisualStateManager.VisualStateGroups>
                            <ContentControl x:Name="ContentContainer" 
                                            ContentTemplate="{TemplateBinding ContentTemplate}" 
                                            Content="{TemplateBinding Content}" 
                                            Foreground="{TemplateBinding Foreground}" 
                                            HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" 
                                            Padding="{TemplateBinding Padding}" 
                                            VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
        <conv:ImageCacheConverter x:Key="imgConv" />
        <conv:VisibilityBooleanConverter x:Key="overlayVisBoolConv"
                                         DefaultVisibility="Collapsed" 
                                         FalseVisibility="Visible" 
                                         TrueVisibility="Collapsed" />
        <conv:ColorBooleanConverter x:Key="colBool" 
                                    DefaultColor="{StaticResource PhoneForegroundBrush}" 
                                    FalseColor="{StaticResource PhoneForegroundBrush}"
                                    TrueColor="{StaticResource PhoneAccentBrush}" />
        <conv:ColorBooleanConverter x:Key="colBoolPowerButton"
                                    DefaultColor="{StaticResource PhoneDisabledBrush}"
                                    FalseColor="{StaticResource PhoneDisabledBrush}"
                                    TrueColor="{StaticResource PhoneAccentBrush}" />
        <Style TargetType="Button" BasedOn="{StaticResource clearButtonStyle}" />
        <Style x:Key="yavcPhoneTextLargeStyle" BasedOn="{StaticResource PhoneTextLargeStyle}" TargetType="TextBlock">
            <Setter Property="TextWrapping" Value="Wrap" />
        </Style>

        <DataTemplate x:Key="dtZoneTemplate">
            <Grid Width="400">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="Auto" />
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>
                <toolkit:ContextMenuService.ContextMenu>
                    <toolkit:ContextMenu>
                        <toolkit:MenuItem Header="pin to Start" Click="PinZone_Click" Tag="{Binding}" />
                    </toolkit:ContextMenu>
                </toolkit:ContextMenuService.ContextMenu>
                <Image Source="{Binding ImageUri, Converter={StaticResource imgConv}}" 
										 Margin="5" Grid.RowSpan="2" Height="96" Width="96"
										 VerticalAlignment="Top" />

                <TextBlock Text="{Binding ZoneTitle}" 
                           Grid.Column="1" 
                           Style="{StaticResource yavcPhoneTextLargeStyle}"
                           VerticalAlignment="Bottom" HorizontalAlignment="Center" />

                <TextBlock Text="{Binding InputTitle}" 
                           Grid.Column="1" Grid.Row="1"
                           Style="{StaticResource PhoneTextTitle3Style}"
                           VerticalAlignment="Top" HorizontalAlignment="Center" />

                <Button Grid.RowSpan="2" Grid.Column="2" Click="TogglePower_Click">
                    <Grid Background="{StaticResource TransparentBrush}" Width="82" Height="82">
                        <Rectangle RadiusY="3.75"
                         RadiusX="3.75"
                         Margin="{StaticResource PhoneMargin}"
                         Fill="{StaticResource PhoneChromeBrush}" />
                        <Rectangle RadiusY="3.75"
                         RadiusX="3.75"
                         StrokeThickness="0.2"
                         Margin="{StaticResource PhoneMargin}"
                         Stroke="{StaticResource PhoneForegroundBrush}" />
                        <Rectangle x:Name="indicatorLight"
                         Margin="18,20,18,0"
                         RadiusY="3.75"
                         RadiusX="3.75"
                         StrokeThickness="0.5"
                         Height="8"
                         VerticalAlignment="Top"
                         Fill="{Binding IsOn, Converter={StaticResource colBoolPowerButton}}" />
                        <Rectangle Margin="18,20,18,0" RadiusY="3.75" RadiusX="3.75"
                         StrokeThickness="0.5" Height="8" VerticalAlignment="Top">
                            <Rectangle.Stroke>
                                <RadialGradientBrush RadiusY="1.096"
                                       RadiusX="1.019"
                                       Center="0.195,-0.098"
                                       GradientOrigin="0.265,0.15">
                                    <GradientStop Color="Black"
                                  Offset="0.689" />
                                    <GradientStop Color="White"
                                  Offset="1" />
                                </RadialGradientBrush>
                            </Rectangle.Stroke>
                        </Rectangle>
                        <TextBlock 
                             Margin="18,16,18,0"
                             Text="{Binding IsOnString}"
                             FontSize="{StaticResource PhoneFontSizeMedium}"
                             TextAlignment="Center"
                             HorizontalAlignment="Center"
                             VerticalAlignment="Center"
                             Foreground="{StaticResource PhoneForegroundBrush}" />
                    </Grid>
                </Button>
                
                <Border Margin="2" Grid.RowSpan="2" Grid.ColumnSpan="3" BorderBrush="{StaticResource PhoneAccentBrush}" BorderThickness="0,0,0,3" />
            </Grid>
        </DataTemplate>
    </Application.Resources>

    <Application.ApplicationLifetimeObjects>
        <!--Required object that handles lifetime events for the application-->
        <shell:PhoneApplicationService 
            Launching="Application_Launching" Closing="Application_Closing" 
            Activated="Application_Activated" Deactivated="Application_Deactivated"/>
    </Application.ApplicationLifetimeObjects>

</Application>